package com.wenhuang.chatgptopen.mapper;

/*
 *@Time：2023/6/3
 *@Author：Jelly
 */

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wenhuang.chatgptopen.pojo.Topic;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TopicMapper extends BaseMapper<Topic> {

    //根据用户id将帖子加入到数据库中
    @Insert("insert into topic(id,user_id,title,content) values (null,#{userId},#{title},#{content})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    Integer addContent(Topic topic);

    //根据用户id和帖子内容删除帖子
    @Delete("delete from topic where user_id = #{userId} and content = #{content}")
    Integer deleteTopic(Topic topic);

    //根据用户id查询用户的所有帖子
    @Select("select * from topic where user_id = #{userId}")
    List<Topic> selectTopicByUserId(Topic topic);

    //根据用户id和标题内容查询帖子
    @Select("select * from topic where user_id = #{userId} and title = #{title}")
    Topic selectTopicByTitleAndUserId(Topic topic);
}
